﻿using System;
using System.Linq;
using Alphaleonis.Win32.Filesystem;
using CueMounter.DokanStructure;

namespace CueMounter
{
	public class DokanDirectoryFactory {
		public static bool CanGetFileProvider(string targetFile) {
			string extension = Path.GetExtension(targetFile).ToLower();
			if(extension == ".cue") {
				return true;
			} else if(BassWaveProvider.SupportedAudioFiles.Contains(extension)) {
				return true;
			}
			return false;
		}

		public static DokanDirectory GetFileProvider(string targetFile) {
			string extension = Path.GetExtension(targetFile).ToLower();
			if(extension == ".cue") {
				return new DokanCueSheetDirectory(targetFile);
			} else if(WaveProviderFactory.TryGetWaveProvider(targetFile)) {
				IWaveProvider waveProvider = WaveProviderFactory.GetWaveProvider(targetFile);
				return new DokanWaveProviderDirectory(Path.GetFileNameWithoutExtension(targetFile), waveProvider);
			}
			return null;
		}
	}
}
